///////////////////////////////////////////////////////////////////////////////////////
//
//	Copyright (c) 2011 staticfunction
//	
//	---------Author Information---------
//
//		Name: James Roland Cabresos
//		Email: j.cabresos@yahoo.com
//		Blog: staticfunction.wordress.com
//
//	---------Author Information---------
//
//	Permission is hereby granted, free of charge, to any person obtaining a copy
//	of this software and associated documentation files (the "Software"), to deal
//	in the Software without restriction, including without limitation the rights
//	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//	copies of the Software, and to permit persons to whom the Software is
//	furnished to do so, subject to the following conditions:
//	
//	The above copyright notice and this permission notice shall be included in
//	all copies or substantial portions of the Software.
//	
//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//	THE SOFTWARE.
//
///////////////////////////////////////////////////////////////////////////////////////

package kola.accessibility
{
	import kola.controls.CheckBox;
	
	import mx.accessibility.AccConst;
	import mx.core.UIComponent;
	import mx.core.mx_internal;
	
	import spark.accessibility.ButtonBaseAccImpl;
	
	use namespace mx_internal;
	
	public class CheckBoxAccImpl extends ButtonBaseAccImpl
	{
		
		//--------------------------------------------------------------------------
		//
		//  Class methods
		//
		//--------------------------------------------------------------------------
		
		/**
		 *  Enables accessibility in the CheckBox class.
		 *
		 *  <p>This method is called by application startup code
		 *  that is autogenerated by the MXML compiler.
		 *  Afterwards, when instances of CheckBox are initialized,
		 *  their <code>accessibilityImplementation</code> property
		 *  will be set to an instance of this class.</p>
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10
		 *  @playerversion AIR 1.5
		 *  @productversion Flex 4
		 */
		public static function enableAccessibility():void
		{
			CheckBox.createAccessibilityImplementation =
				createAccessibilityImplementation;
		}
		
		/**
		 *  @private
		 *  Creates a CheckBox's AccessibilityImplementation object.
		 *  This method is called from UIComponent's
		 *  initializeAccessibility() method.
		 */
		mx_internal static function createAccessibilityImplementation(
			component:UIComponent):void
		{
			component.accessibilityImplementation =
				new CheckBoxAccImpl(component);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		/**
		 *  Constructor.
		 *
		 *  @param master The UIComponent instance that this AccImpl instance
		 *  is making accessible.
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10
		 *  @playerversion AIR 1.5
		 *  @productversion Flex 4
		 */
		public function CheckBoxAccImpl(master:UIComponent)
		{
			super(master);
			
			role = AccConst.ROLE_SYSTEM_CHECKBUTTON;
		}
	
		override public function get_accState(childID:uint):uint
		{
			var accState:uint = getState(childID);
			
			switch(CheckBox(master).value)
			{	
				case CheckBox.INDETERMINATE:
					accState |= AccConst.STATE_SYSTEM_MIXED;
					break;
				case CheckBox.CHECKED:
					accState |= AccConst.STATE_SYSTEM_CHECKED;
					break;
			}
			
			return accState;
		}
		
		/**
		 *  @private
		 *  IAccessible method for returning the default action of
		 *  the CheckBox, which is Check or UnCheck depending on the state.
		 *
		 *  @param childID uint
		 *
		 *  @return DefaultAction Check or UnCheck.
		 */
		override public function get_accDefaultAction(childID:uint):String
		{
			return CheckBox(master).value;
		}
	}
}